<template>
	<div class="register">
		<!-- 退回按钮 -->
		<Back 
			@back = "back"
		></Back>
		<!-- 公共部分 -->
		<Register
			ref = "common"
			:showOrHide = "showOrHide"
			@rigster = "rigster"
			@setImg = "setImg"
			@readURL = "readURL"
		></Register>
	</div>
</template>

<script type="text/javascript">
// eslint-disable-next-line
/* eslint-disable */
import Register from "../components/common.vue"
import Back from '../components/back.vue'
import { MessageBox } from 'mint-ui'
import {mixin} from "../mixin.js"
import form from '../../common/js/form.js'
export default {
	mixins: [mixin],
	name:'register',
	components: {
		Register,
		Back
	},
	data() {
		return {
			showOrHide: false,
			file:null,
		}
	},
	methods: {
		rigster(username,password) {
			username = username.trim();
			password = password.trim();
			
			// 检测name
			if(!username){
				MessageBox("","请输入昵称")
				return ;
			}
			// 检测pass
			if(!password){
				MessageBox("","请输入密码")
				return ;
			}

			api.register({
				user_name: username,
				user_pass: password
			}).then(res=>{
				if(res.code===0){
					MessageBox("",res.message).then(action=>{
						if(action=="confirm"){
							this.$router.push({
								name: 'login'
							})
						}
					})
				}
			}).catch(res=>{
				console.log("register res",res)
				if(res.code===1002){
					// 注册失败
					MessageBox("",res.message).then(action=>{
						if(action=="confirm"){
							var input = this.$refs.common.$refs
							input.username.value = ''
							input.password.value = ""
						}
					})
				}
			})

		},
		back() {
			this.$router.push({
				name: 'login'
			})
		}
	}
}
</script>